package com.tiantianfresh.view.controller;

import com.tiantianfresh.model.pojo.AJAXResult;
import com.tiantianfresh.model.pojo.Address;
import com.tiantianfresh.model.pojo.OrderAlipay;
import com.tiantianfresh.model.pojo.OrderSpecific;
import com.tiantianfresh.view.service.ShopCheckoutService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author FANGAO
 * @date 2021/12/4 - 下午 21:27
 */
@Controller
@RequestMapping("/shopCheckout")
public class ShopCheckoutController {
    @Autowired
    private ShopCheckoutService shopCheckoutService;

    @ResponseBody
    @RequestMapping("/queryChopCheckoutState")
    public Object queryChopCheckoutStateAll(@RequestParam(required = false,defaultValue = "0") Integer userid,String orderid){
        AJAXResult result = new AJAXResult();
        Map<String,Object> map = new HashMap<>();
        map.put("userid",userid);
        map.put("orderid",orderid);
        List<OrderSpecific> orderSpecificList = shopCheckoutService.queryChopCheckoutStateAll(map);
        if(orderSpecificList!=null){
            result.setData(orderSpecificList);
            result.setSuccess(true);
        }else{
            result.setSuccess(false);
        }
        return result;
    }
    @ResponseBody
    @RequestMapping("/payment")
    public Object payment(@RequestParam(required = false,defaultValue = "0") Integer userid,Integer addressId,String orderid){
        AJAXResult result = new AJAXResult();
        Map<String,Object> map = new HashMap<>();
        map.put("userid",userid);
        map.put("addressId",addressId);
        map.put("orderid",orderid);
        OrderAlipay orderAlipay = shopCheckoutService.payment(map);
        if (orderAlipay!=null){
            result.setSuccess(true);
            result.setData(orderAlipay);
        }else {
            result.setSuccess(false);
        }

        return result;
    }
    @ResponseBody
    @RequestMapping("/queryAddressAll")
    public Object queryAddressAll(Integer userid){
        AJAXResult result = new AJAXResult();
        List<Address> addressList = shopCheckoutService.queryAddressAll(userid);
        if(addressList!=null){
            result.setData(addressList);
            result.setSuccess(true);
        }else{
            result.setSuccess(false);
        }
        return result;
    }
    @ResponseBody
    @RequestMapping("/deleteShopcheckout")
    public Object deleteShopcheckout(Integer addid){
        AJAXResult result = new AJAXResult();
        Map<String,Integer> map = new HashMap<>();
        map.put("addid",addid);
        result.setSuccess(shopCheckoutService.deleteShopcheckout(map));
        return result;
    }
}
